<template>
    <Card :padding="0" style="margin-top:8px;" v-if="messageData.length>0">
        <div class="word-template-title">
            <span>提醒</span>
            <!-- <a class=""><i class="ivu-icon ivu-icon-ios-close-empty"></i></a> -->
        </div>
        
         <div class="word-template-list">
            <p v-for="item in messageData"> {{item}}</p>
        </div>
        <!-- <ul class="word-template-list">
            <li> 今天是该同学的生日！</li>
        </ul> -->
    </Card>
</template>
<style scoped>
    .word-template-title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: #eaeaea;
        height: 25px;
        padding: 0 5px;
    }
    
    .word-template-list p {
        padding: 10px 0
    }
</style>
<script>
    import configService from 'service/configService.js'
    import thirdService from 'service/thirdService.js'
    import {
        timeDiff
    } from '@/libs/filter.js'
    export default {
        name: 'remindList',
        props: {
            studentObj: Object,
        },
        data() {
            return {
                kidBirthdayNotice: '',
                payAgainNotice: '',
                rechargeAtFirstMonthNotice: '',
                messageData: []
            }
        },
        watch: {
            studentObj(newVal, oldVal) {
                let studentObj = newVal
                this.findBalanceSurPlus()
                this.getStudentBirthdayRemind()
                this.getCourseAccountListByStudentId()
            }
        },
        mounted() {
            this.getLifyCycleList()
            if (this.studentObj.id) {
                this.findBalanceSurPlus()
                this.getStudentBirthdayRemind()
                this.getCourseAccountListByStudentId()
            }

        },
        methods: {
            //学生生日   首差  剩余课时
            async getLifyCycleList() {
                let jsondata = await configService.getLifyCycleList()
                this.kidBirthdayNotice = jsondata.kidBirthdayNotice
                this.payAgainNotice = jsondata.payAgainNotice
                this.rechargeAtFirstMonthNotice = jsondata.rechargeAtFirstMonthNotice
            },
            //补差期剩余时间
            async findBalanceSurPlus() {
                let studentId = this.studentObj.id
                let jsondata = await thirdService.findBalanceSurPlus({
                    'studentId': studentId
                })
                if (jsondata.succes) {
                    let dataDiff = parseInt(jsondata.data)
                    if (this.rechargeAtFirstMonthNotice <= dataDiff) {
                        this.messageData.push('距离补差期结束' + jsondata.data)
                    }
                }
            },
            //剩余课时
            async getCourseAccountListByStudentId() {
                let data = {
                    'studentId': this.studentObj.id
                }
                let jsondata = await thirdService.getCourseAccountListByStudentId(data)
                if (jsondata.code == 200) {
                    let courseList = jsondata.data
                    let majorCourseData = courseList.filter((item, index) => {
                        return item.balanceType == 'MAJOR'
                    })

                    if (majorCourseData.length > 0) {
                        let leftClassHour = majorCourseData[0].leftClassHour
                        if (leftClassHour <= this.payAgainNotice) {
                            this.messageData.push('主修课程还剩下' + leftClassHour + '课时')
                        }
                    }


                }
            },
            //学生生日提醒
            async getStudentBirthdayRemind() {
                let birthday = this.studentObj.birthday
                let daysDiff = timeDiff(birthday)
                if (daysDiff <= this.kidBirthdayNotice) {
                    this.messageData.push('距离该学生生日还有' + daysDiff + '天')
                }
            },
        }


    }
</script>